package gek.uni.aspirant.ocl.parser.mptree.tree.utils;

import gek.uni.aspirant.ocl.parser.mptree.tree.INode;

import org.eclipse.ocl.expressions.OCLExpression;

public class TreeUtils {
  public String getVarNameForExpression(OCLExpression exp, INode startNode) {
    String expName = exp.getName();
    String[] splits = expName.split("\\.");
    return getNameForExpression(splits, startNode);
  }

  public static String getNameForExpression(String[] splits, INode startNode) {
    if (splits.length == 0)
      return "";
    StringBuilder bldr = new StringBuilder();
    for (String oclVariableName : splits) {
      String prologVariableName = OfflineUtils
          .createPrologVariableName(oclVariableName);
      bldr.append(prologVariableName);
      bldr.append("_");
    }
    if (bldr.length() > 0)
      bldr.deleteCharAt(bldr.length() - 1);
    
    return bldr.toString();
  }
}
